home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / error.c < prev    next >
C/C++ Source or Header  |  1990-08-16  |  2KB  |  94 lines

  1. /*
  2.  * @(#)error.c    1.2  3/18/87
  3.  */
  4. #include "error.h"
  5. #include "nodes.h"
  6.  
  7. int numberOfSyntaxErrors, numberOfSemanticErrors;
  8. char error_buffer[256];
  9.  
  10. int We_Are_Skipping = 0;
  11.  
  12. void BeginSyntaxErrorMessage(flag)
  13. int flag;
  14. {
  15.   register int i;
  16.   fprintf(stdout, "\"%s\", line %d\n%s",
  17.     currentFileName, nextLineNumber, 
  18.     (int) lineBuffer.buffer[0] == -1 ? "<EOF>\n" : lineBuffer.buffer);
  19.   for (i = 0; i < currentPosition; i++) {
  20.     if (lineBuffer.buffer[i] == '\t') (void) fputc('\t', stdout);
  21.     else (void) fputc(' ', stdout);
  22.   }
  23.   fprintf(stdout, "^\n%s", flag ? "Syntax error: " : "");
  24.   numberOfSyntaxErrors++;
  25. }
  26.  
  27. IllegalCharacter(c)
  28. char c;
  29. {
  30.   char *dummy = "z";
  31.  
  32.   if (We_Are_Skipping) return;
  33.   BeginSyntaxErrorMessage(1);
  34.   ErrorWrite("Illegal character in source ");
  35.   *dummy = c;
  36.   ErrorWrite(dummy);
  37.   EndErrorMessage();
  38. }
  39.  
  40. UnexpectedEndOfFile()
  41. {
  42.   BeginSyntaxErrorMessage(1);
  43.   ErrorWrite("unexpected end of file");
  44.   EndErrorMessage();
  45. }
  46.  
  47. void NotImplemented(p, s)
  48. NodePtr p;
  49. char *s;
  50. {
  51.   BeginErrorMessage(p);
  52.   ErrorWrite("Not Implemented: ");
  53.   ErrorWrite(s);
  54.   EndErrorMessage();
  55. }
  56.  
  57. void CheckForErrors()
  58. {
  59.   if (numberOfSyntaxErrors != 0 || numberOfSemanticErrors != 0) {
  60.     fprintf(stdout, "Compilation aborted.\n");
  61.     exit(1);
  62.   }
  63. }
  64.  
  65. /*VARARGS2*/
  66. void ErrorMessage(p, format, args)
  67. NodePtr p;
  68. char *format;
  69. int args;
  70. {
  71.   BeginErrorMessage(p);
  72.   _doprnt(format, &args, stdout);
  73.   EndErrorMessage();
  74. }
  75.  
  76. /*VARARGS2*/
  77. void WarningMessage(p, format, args)
  78. NodePtr p;
  79. char *format;
  80. int args;
  81. {
  82.   BeginWarningMessage(p);
  83.   _doprnt(format, &args, stdout);
  84.   EndErrorMessage();
  85. }
  86.  
  87. yyerror(s)
  88. char *s;
  89. {
  90.   BeginSyntaxErrorMessage(0);
  91.   ErrorWrite(s);
  92.   EndErrorMessage();
  93. }
  94.